﻿using NodaTime;
using SqlSugar;
using System;

namespace DataSyncCom
{
    /// <summary>
    /// MySql数据库操作
    /// </summary>
    public class DbHelperMySql
    {
         

        #region SqlSugar
        public static SqlSugarClient GetSqlSugarDb()
        {
            SqlSugarClient db = new SqlSugarClient(
                new ConnectionConfig()
                {
                    ConnectionString = "Data Source='pe-wz9v11dum5w2lzeyq.rwlb.rds.aliyuncs.com';port=3306;User Id='rootpermission';pwd='Abcd1234!';charset='utf8';pooling=true",
                    //ConnectionString = "Data Source='beaver.mysql.polardb.rds.aliyuncs.com';port=3306;User Id='rootpermission';pwd='Abcd1234!';charset='utf8';pooling=true",
                    //ConnectionString =   "server='49.4.70.226';port=3306;uid='root';pwd='aaabbb123';charset='utf8';pooling=true",
                    DbType = SqlSugar.DbType.MySql,//设置数据库类型
                    IsAutoCloseConnection = true,//自动释放数据务，如果存在事务，在事务结束后释放
                    InitKeyType = InitKeyType.Attribute //从实体特性中读取主键自增列信息
                }); 
            return db;
        }
        #endregion
    }

    public class DateTimeExt
    {
        public static DateTime GetCstDateTime()
        {
            Instant now = SystemClock.Instance.GetCurrentInstant();
            var shanghaiZone = DateTimeZoneProviders.Tzdb["Asia/Shanghai"];
            return now.InZone(shanghaiZone).ToDateTimeUnspecified();
        }
    }
    /// <summary>
    /// DateTime.Now.ToCstTime();
    /// </summary>
    public static class DateTimeExtentions
    {
        public static DateTime ToCstTime(this DateTime time)
        {
            return DateTimeExt.GetCstDateTime();
        }
    }
}

